package be.ipl.streams.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import be.ipl.streams.exceptions.ArgumentInvalideException;

public final class Util {
	static {
		Properties props = new Properties();
		
		try {
//			InputStream is = Class.class.
//					getResourceAsStream("ejbModule/constantes.props");
			
			InputStream is = new FileInputStream(
					"streams_EJB/ejbModule/constantes.props");
			
			props.load(is);
			is.close();
		} catch (IOException e) {
			System.err.println(e.getMessage());
		}
		
		DELAI_START_GAME = Integer.parseInt(props.getProperty(
				"delay start game", "5"));
		DELAI_NEXT_TURN = Integer.parseInt(props.getProperty(
				"delay next turn", "5"));
		
	}
	
	public static final int DELAI_START_GAME;
	public static final int DELAI_NEXT_TURN;
	
	public static void checkObject(Object o) throws ArgumentInvalideException {
		if (o == null)
			throw new ArgumentInvalideException();
	}
	
	public static void checkString(String s) throws ArgumentInvalideException {
		checkObject(s);
		if (s.trim().equals(""))
			throw new ArgumentInvalideException();
	}
	public static void checkNegativeOrZero(double d) throws ArgumentInvalideException {
		if (d > 0.0)
			throw new ArgumentInvalideException();
	}
	public static void checkPositiveOrZero(double d) throws ArgumentInvalideException {
		if (d < 0)
			throw new ArgumentInvalideException();
	}
	public static void checkPositive(double d) throws ArgumentInvalideException {
		if (d<=0.00001)
			throw new ArgumentInvalideException();
	}
	
	public static void checkPositive(int i) throws ArgumentInvalideException {
		if (i<=0)
			throw new ArgumentInvalideException();
	}
}
